package com.wn.pettyloan.controller;

import com.wn.pettyloan.entity.ContractTemplate;
import com.wn.pettyloan.service.ContractTemplateService;
import com.wn.pettyloan.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: pettyloan 合同模板表
 * @ClassName ContractTemplateControllerr
 * @description: 合同模板的crud
 * @author: 国雨浓
 * @create: 2022-12-07 15:22
 **/
@RestController
@RequestMapping("contractTemplate")
public class ContractTemplateController {
    @Resource
    private ContractTemplateService contractTemplateService;


    /*
      * @Author 国雨浓
      * @Description  查询全部合同模板
      * @Date 12:05 2022/12/8
      * @Param []
      * @return com.wn.pettyloan.util.Result
      **/
    @GetMapping("/selectAll")
    public Result selectAll(){
        List<ContractTemplate> contractTemplates = contractTemplateService.selectAll();
        return Result.ok().data("contractTemplatesList",contractTemplates);
    }

    @PostMapping("/insertSelective")
    public Result insertSelective(@RequestBody ContractTemplate contractTemplate){
        int i = contractTemplateService.insertSelective(contractTemplate);
        if (i > 0) {
            return Result.ok();
        }else {
            return Result.error("");
        }
    }
    /**
     * @Description: 根据产品ID查询对应的合同模板
     * @param productId
     * @return: com.wn.pettyloan.util.Result
     * @Author: Morsera
     * @Date: 2022/12/15 15:17
     */
    @GetMapping("{productId}")
    public Result selByProductId(@PathVariable Long productId){
        ContractTemplate contractTemplates = contractTemplateService.selByProductId(productId);
        return Result.ok().data("contractTemplate", contractTemplates);

    }
    /**
     * @Description: 根据合同模板ID修改合同模板内容
     * @param contractTemplate
     * @return: com.wn.pettyloan.util.Result
     * @Author: Morsera
     * @Date: 2022/12/15 15:21
     */
    @PutMapping("/update")
    public Result update(@RequestBody ContractTemplate contractTemplate) {
        int i = contractTemplateService.updateById(contractTemplate);
        if (i > 0) {
            return Result.ok();
        } else {
            return Result.error("");
        }

    }
}

